<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>{$meta_title}-狂雨小说CMS</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="__ADMIN__/css/admin.css"></head>
  <link rel="stylesheet" href="__ADMIN__/css/font.css"></head>
<body>
  <div class="layui-card layui-card-open">
    <div class="layui-card-body">
      <form class="layui-form" lay-filter="relation" action="{:url()}">
        <div class="layui-form-item">
          <label class="layui-form-label">关联页名称</label>
          <div class="layui-input-block">
            <input type="text" name="relation[title]" lay-verify="required" class="layui-input" value="">
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label">从页中提取</label>
          <div class="layui-input-block">
            <select name="relation[page]">
              <option value="default">默认内容页</option>
              <optgroup label="关联页" id="option_view">
              </optgroup>
            </select>
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label">是否章节列表</label>
          <div class="layui-input-block">
            <input type="radio" lay-filter="relation_chapter" name="relation[chapter]" value="1" title="是">
            <input type="radio" lay-filter="relation_chapter" name="relation[chapter]" value="0" title="否" checked>
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label">获取区间</label>
          <div class="layui-input-block">
            <textarea name="relation[section]" placeholder="区域开始代码[内容]区域结束代码" class="layui-textarea"></textarea>
            <div class="layui-form-mid layui-word-aux">
              通配符<a href="javascript:;" onclick="insertText('relation[section]','[内容{num}]',1)"> [内容] </a>
            </div>
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label">网址规则</label>
          <div class="layui-input-block">
            <textarea name="relation[url_rule]" lay-verify="required" placeholder="默认获取a标签链接，示例：&lt;a href=&quot;http://demo.com/[内容1]/[内容2]&quot;&gt;(*)&lt;/a&gt;" class="layui-textarea"></textarea>
            <div class="layui-form-mid layui-word-aux" relation_rule>
              正则<a href="javascript:;" onclick="insertReg('relation[url_rule]','(*)')"> (*) </a>
              通配符<a href="javascript:;" onclick="insertText('relation[url_rule]','[内容{num}]')"> [内容] </a>
              <a relation_rule_a class="layui-hide" href="javascript:;" onclick="insertText('relation[url_rule]','[章节标题]')"> [章节标题] </a>
            </div>
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label">拼接网址</label>
          <div class="layui-input-block">
            <input type="text" name="relation[url_merge]" placeholder="默认拼接所有[内容]标签，示例：http://www.demo.com/[内容1]-[内容2].html" class="layui-input">
            <div class="layui-form-mid layui-word-aux">
              正则<a href="javascript:;" onclick="insertReg('relation[url_merge]','(*)')"> (*) </a>
              通配符<a href="javascript:;" onclick="insertText('relation[url_merge]','[内容{num}]')"> [内容] </a>
            </div>
          </div>
        </div>
        <div class="layui-form-item">
          <div class="layui-input-block">
            <input name="index" type="hidden" value="{$index|default=""}" />
            <button class="layui-btn" lay-submit lay-filter="relation" type="submit">提交</button>
          </div>
        </div>
      </form>
    </div>
  </div>
  <script type="text/javascript" src="__STATIC__/jquery/jquery.min.js"></script>
  <script type="text/javascript" src="__ADMIN__/lib/layui/layui.js"></script>
  <script type="text/javascript" src="__ADMIN__/js/admin.js"></script>
  <script type="text/javascript" src="__ADMIN__/js/collect.js"></script>
  <script id="option" type="text/html">
  {{#  layui.each(d, function(index, item){ }}
    <option value="{{ index }}">{{ item.title }}</option>
  {{#  }); }}
</script>
  <script type="text/javascript">
    layui.use(['form','laytpl'],function() {
      var form = layui.form;
      var laytpl = layui.laytpl;

      if(parent.$('[name="relation_url"]').val()){
        var data=$.parseJSON(parent.$('[name="relation_url"]').val());
        laytpl($('#option').html()).render(data, function(html){
            $('#option_view').html(html);
        });
        form.render('select');
      }

      {present name="index"}
        var index=$('[name="index"]').val();
        if(data[index]['chapter']==1){
            $('[relation_rule] [relation_rule_a]').removeClass('layui-hide');
        }
        form.val("relation", {
          "relation[title]": data[index]['title'],
          "relation[page]": data[index]['page'],
          "relation[chapter]": data[index]['chapter'],
          "relation[section]": data[index]['section'],
          "relation[url_rule]": data[index]['url_rule'],
          "relation[url_merge]": data[index]['url_merge']
        });
      {/present}

      form.on('radio(relation_chapter)', function(data){
        if(data.value==1){
          $('[relation_rule] [relation_rule_a]').removeClass('layui-hide');
        }else{
          $('[relation_rule] [relation_rule_a]').addClass('layui-hide');
        }
      });
    });
  </script>
</body>
</html>